﻿using System;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using WMSABL;
using SYDZ.WMS.DBUtility;
using ElectronicWMSA.Comm.ClassFiles;

namespace ElectronicWMSA.Warehouse
{
    public partial class List_GZStockFrm : Form
    {
        #region

        private string strWhere2 = "";
        PublicDataSet bll_PublicDataSet = new PublicDataSet();
        public List_GZStockFrm()
        {
            InitializeComponent();
            this.pageControl2.PageCurrent = 1;
            this.pageControl2.PageSize = 50;
            this.pageControl2.Bind();
            cmbType.SelectedIndex = 0;
        }
        #endregion

     
        private int DBindData2()
        {
            Comm.Forms.MsControls.PageData pageData = new Comm.Forms.MsControls.PageData();
            pageData.TableName = "T_GCStock";
            pageData.PrimaryKey = "NID";
            pageData.OrderStr = "NID";
            pageData.PageIndex = this.pageControl2.PageCurrent;
            pageData.PageSize = this.pageControl2.PageSize;
            pageData.QueryCondition = strWhere2;
            pageData.QueryFieldName = "*";

            this.pageControl2.bindingSource.DataSource = pageData.QueryDataTable().Tables[0];
            this.pageControl2.bindingNavigator.BindingSource = pageControl2.bindingSource;
            this.dataGridView2.AutoGenerateColumns = false;
            this.dataGridView2.DataSource = this.pageControl2.bindingSource;
            this.dataGridView2.ClearSelection();
            this.dataGridView2.CurrentCell = null;
            return pageData.TotalCount;
        }
        private int pageControl2_EventPaging(Comm.Forms.MsControls.EventPagingArg e)
        {
            return DBindData2();
        }
        private void dataGridView2_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush b = new SolidBrush(dataGridView2.RowHeadersDefaultCellStyle.ForeColor);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), dataGridView2.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
        }
        private void btnSearch2_Click(object sender, EventArgs e)
        {
            if (!SystemVariable.VaildationPermission("查询")) return;
            strWhere2 = " 1=1 ";
            if (!string.IsNullOrEmpty(txt_RU.Text))
            {
                this.strWhere2 += "   and PutList_NO like '%" + txt_RU.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txt_CHU.Text))
            {
                this.strWhere2 += "   and PickList_NO like '%" + txt_CHU.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txt_PO.Text))
            {
                this.strWhere2 += "   and OutList_NO like '%" + txt_PO.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txt_point.Text))
            {
                this.strWhere2 += "   and Posiont1 like '%" + txt_point.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(txt_machine.Text))
            {
                this.strWhere2 += "   and   Replace(Product_Model,' ','')  like '%" + txt_machine.Text.Trim() + "'";
            }
            if (!string.IsNullOrEmpty(txt_Seri.Text))
            {
                this.strWhere2 += "   and Serial_Number like '%" + txt_Seri.Text.Trim() + "%'";
            }
            if (!string.IsNullOrEmpty(cmbType.Text))
            {
                this.strWhere2 += "   and BK03 like '%" + cmbType.Text.Trim() + "%'";
            }
            this.pageControl2.Bind();
        }

        private void button5_Click(object sender, EventArgs e)
        {
            DataTable dt = StrDBind(strWhere2);
            ExPut.GetNopiExcel(dt);
        }
        private DataTable StrDBind(string Where)
        {
            DataTable dt = new DataTable();

            string SelectSQL = "";
            SelectSQL = "   select  PutList_NO,OutList_NO as 'PO',[PickList_NO] as'装箱单',[BanHao] as '板号',[Posiont1] as '库位',[Product_Model] as '机型',[Serial_Number] as '序列号',[Update_UserID] as '扫描人',[BK03] as '类型', [BK04] as'出库人ID',[BK05] as '设备号',BK07 as '类型',BK08 AS '出库时间',Bk10 as '仕向地'      from [T_GCStock]   ";
            if (Where != "")
            {
                SelectSQL += " where  " + Where + "   ";
            }
            dt = DbHelperSQL.ExecuteDataTable(SelectSQL);
            return dt;
        }
        #region  Close
        private void linkLabelClose_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPages();
        }

        private void linkLabellinkLabelCloseAll_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseAllTabPages();
        }

        private void linkLabelCloseElse_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            Main._Main.CloseTabPageElse();
        }
        #endregion

    }
}
